/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GCSOptions.java
 *
 * Created on 19.12.2011, 19:39:18
 */
package com.transas.zorlog.ui;

import java.util.List;
import javax.swing.JComboBox;

/**
 *
 * @author amalikov
 */
@SuppressWarnings("unchecked")
public class GCSOptions extends javax.swing.JPanel {

	/** Creates new form GCSOptions */
	public GCSOptions(List<String> valueNames) {
		initComponents();
		initComboboxes(valueNames);
	}

	public void readValues(AppConfig appConfig) {
		if ("serial".equals(appConfig.getOption(gr, "link")))
			serial.setSelected(true);
		else
			udp.setSelected(true);

		comPort.setText(appConfig.getOption(gr, "comport"));
		baudRate.setText(appConfig.getOption(gr, "baudrate"));
		selfAddr.setText(appConfig.getOption(gr, "self"));
		selfPort.setText(appConfig.getOption(gr, "selfport"));
		remoteAddr.setText(appConfig.getOption(gr, "remote"));
		remotePort.setText(appConfig.getOption(gr, "remoteport"));
		state.setSelectedItem(appConfig.getOption(gr, "state"));
		roll.setSelectedItem(appConfig.getOption(gr, "roll"));
		pitch.setSelectedItem(appConfig.getOption(gr, "pitch"));
		heading.setSelectedItem(appConfig.getOption(gr, "heading"));
		airspeed.setSelectedItem(appConfig.getOption(gr, "airspeed"));
		baroalt.setSelectedItem(appConfig.getOption(gr, "baroalt"));
		vspeed.setSelectedItem(appConfig.getOption(gr, "vspeed"));
		course.setSelectedItem(appConfig.getOption(gr, "course"));
		gspeed.setSelectedItem(appConfig.getOption(gr, "gspeed"));
		latitude.setSelectedItem(appConfig.getOption(gr, "latitude"));
		longitude.setSelectedItem(appConfig.getOption(gr, "longitude"));
		altitude.setSelectedItem(appConfig.getOption(gr, "altitude"));
		rpm.setSelectedItem(appConfig.getOption(gr, "rpm"));
		temp1.setSelectedItem(appConfig.getOption(gr, "temp1"));
		temp2.setSelectedItem(appConfig.getOption(gr, "temp2"));
		aileron.setSelectedItem(appConfig.getOption(gr, "aileron"));
		elevator.setSelectedItem(appConfig.getOption(gr, "elevator"));
		rudder.setSelectedItem(appConfig.getOption(gr, "rudder"));
		throttle.setSelectedItem(appConfig.getOption(gr, "throttle"));
		flaps.setSelectedItem(appConfig.getOption(gr, "flaps"));
		failures.setSelectedItem(appConfig.getOption(gr, "failures"));
		voltage.setSelectedItem(appConfig.getOption(gr, "voltage"));
		current.setSelectedItem(appConfig.getOption(gr, "current"));
		fuel.setSelectedItem(appConfig.getOption(gr, "fuel"));
	}

	public void writeValues(AppConfig appConfig) {
		appConfig.setOption(gr, "link", serial.isSelected() ? "serial" : "udp");
		appConfig.setOption(gr, "comport", comPort.getText());
		appConfig.setOption(gr, "baudrate", baudRate.getText());
		appConfig.setOption(gr, "self", selfAddr.getText());
		appConfig.setOption(gr, "selfport", selfPort.getText());
		appConfig.setOption(gr, "remote", remoteAddr.getText());
		appConfig.setOption(gr, "remoteport", remotePort.getText());
		appConfig.setOption(gr, "state", state.getSelectedItem().toString());
		appConfig.setOption(gr, "roll", roll.getSelectedItem().toString());
		appConfig.setOption(gr, "pitch", pitch.getSelectedItem().toString());
		appConfig.setOption(gr, "heading", heading.getSelectedItem().toString());
		appConfig.setOption(gr, "airspeed", airspeed.getSelectedItem().toString());
		appConfig.setOption(gr, "baroalt", baroalt.getSelectedItem().toString());
		appConfig.setOption(gr, "vspeed", vspeed.getSelectedItem().toString());
		appConfig.setOption(gr, "course", course.getSelectedItem().toString());
		appConfig.setOption(gr, "gspeed", gspeed.getSelectedItem().toString());
		appConfig.setOption(gr, "latitude", latitude.getSelectedItem().toString());
		appConfig.setOption(gr, "longitude", longitude.getSelectedItem().toString());
		appConfig.setOption(gr, "altitude", altitude.getSelectedItem().toString());
		appConfig.setOption(gr, "rpm", rpm.getSelectedItem().toString());
		appConfig.setOption(gr, "temp1", temp1.getSelectedItem().toString());
		appConfig.setOption(gr, "temp2", temp2.getSelectedItem().toString());
		appConfig.setOption(gr, "aileron", aileron.getSelectedItem().toString());
		appConfig.setOption(gr, "elevator", elevator.getSelectedItem().toString());
		appConfig.setOption(gr, "rudder", rudder.getSelectedItem().toString());
		appConfig.setOption(gr, "throttle", throttle.getSelectedItem().toString());
		appConfig.setOption(gr, "flaps", flaps.getSelectedItem().toString());
		appConfig.setOption(gr, "failures", failures.getSelectedItem().toString());
		appConfig.setOption(gr, "voltage", voltage.getSelectedItem().toString());
		appConfig.setOption(gr, "current", current.getSelectedItem().toString());
		appConfig.setOption(gr, "fuel", fuel.getSelectedItem().toString());
	}
	
	private void initComboboxes(List<String> valueNames) {
		final JComboBox[] comboBoxes = new JComboBox[]{
			state, roll, pitch, heading, airspeed, baroalt, vspeed, course, gspeed, 
			latitude, longitude, altitude, rpm, temp1, temp2, aileron, elevator, 
			rudder, throttle, flaps, failures, voltage, current, fuel};
		for (JComboBox comboBox : comboBoxes) {
			comboBox.removeAllItems();
			for (String valueName : valueNames)
				comboBox.addItem(valueName);
		}
	}
	
	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        selfAddr = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        remoteAddr = new javax.swing.JTextField();
        remotePort = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel28 = new javax.swing.JLabel();
        selfPort = new javax.swing.JTextField();
        serial = new javax.swing.JRadioButton();
        udp = new javax.swing.JRadioButton();
        jLabel29 = new javax.swing.JLabel();
        comPort = new javax.swing.JTextField();
        jLabel30 = new javax.swing.JLabel();
        baudRate = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        aileron = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        temp2 = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        temp1 = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        heading = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        airspeed = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        baroalt = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        vspeed = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        course = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        gspeed = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        latitude = new javax.swing.JComboBox();
        jLabel14 = new javax.swing.JLabel();
        longitude = new javax.swing.JComboBox();
        jLabel15 = new javax.swing.JLabel();
        altitude = new javax.swing.JComboBox();
        jLabel16 = new javax.swing.JLabel();
        rpm = new javax.swing.JComboBox();
        pitch = new javax.swing.JComboBox();
        roll = new javax.swing.JComboBox();
        state = new javax.swing.JComboBox();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        elevator = new javax.swing.JComboBox();
        jLabel21 = new javax.swing.JLabel();
        rudder = new javax.swing.JComboBox();
        jLabel22 = new javax.swing.JLabel();
        throttle = new javax.swing.JComboBox();
        jLabel23 = new javax.swing.JLabel();
        flaps = new javax.swing.JComboBox();
        jLabel24 = new javax.swing.JLabel();
        failures = new javax.swing.JComboBox();
        jLabel25 = new javax.swing.JLabel();
        voltage = new javax.swing.JComboBox();
        jLabel26 = new javax.swing.JLabel();
        current = new javax.swing.JComboBox();
        jLabel27 = new javax.swing.JLabel();
        fuel = new javax.swing.JComboBox();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Connection"));
        jPanel1.setLayout(null);

        jLabel1.setText("Self:");
        jPanel1.add(jLabel1);
        jLabel1.setBounds(80, 60, 70, 20);
        jPanel1.add(selfAddr);
        selfAddr.setBounds(150, 60, 140, 20);

        jLabel2.setText("Remote:");
        jPanel1.add(jLabel2);
        jLabel2.setBounds(80, 90, 70, 20);
        jPanel1.add(remoteAddr);
        remoteAddr.setBounds(150, 90, 140, 20);
        jPanel1.add(remotePort);
        remotePort.setBounds(360, 90, 80, 20);

        jLabel3.setText("Port:");
        jPanel1.add(jLabel3);
        jLabel3.setBounds(310, 90, 50, 20);

        jLabel28.setText("Port:");
        jPanel1.add(jLabel28);
        jLabel28.setBounds(310, 60, 50, 20);
        jPanel1.add(selfPort);
        selfPort.setBounds(360, 60, 80, 20);

        buttonGroup1.add(serial);
        serial.setText("Serial");
        jPanel1.add(serial);
        serial.setBounds(10, 20, 60, 23);

        buttonGroup1.add(udp);
        udp.setText("UDP");
        jPanel1.add(udp);
        udp.setBounds(10, 60, 60, 23);

        jLabel29.setText("COM port:");
        jPanel1.add(jLabel29);
        jLabel29.setBounds(80, 20, 70, 20);
        jPanel1.add(comPort);
        comPort.setBounds(150, 20, 110, 20);

        jLabel30.setText("Baud rate:");
        jPanel1.add(jLabel30);
        jLabel30.setBounds(280, 20, 70, 20);
        jPanel1.add(baudRate);
        baudRate.setBounds(350, 20, 90, 20);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Values"));
        jPanel2.setLayout(null);

        jLabel4.setText("Aileron:");
        jPanel2.add(jLabel4);
        jLabel4.setBounds(240, 110, 90, 20);

        jPanel2.add(aileron);
        aileron.setBounds(330, 110, 114, 22);

        jLabel5.setText("Temp2:");
        jPanel2.add(jLabel5);
        jLabel5.setBounds(240, 80, 90, 20);

        jPanel2.add(temp2);
        temp2.setBounds(330, 80, 114, 22);

        jLabel6.setText("Temp1:");
        jPanel2.add(jLabel6);
        jLabel6.setBounds(240, 50, 90, 20);

        jPanel2.add(temp1);
        temp1.setBounds(330, 50, 114, 22);

        jLabel7.setText("Heading:");
        jPanel2.add(jLabel7);
        jLabel7.setBounds(20, 110, 90, 20);

        jPanel2.add(heading);
        heading.setBounds(110, 110, 114, 22);

        jLabel8.setText("Airspeed:");
        jPanel2.add(jLabel8);
        jLabel8.setBounds(20, 140, 90, 20);

        jPanel2.add(airspeed);
        airspeed.setBounds(110, 140, 114, 22);

        jLabel9.setText("Baroalt:");
        jPanel2.add(jLabel9);
        jLabel9.setBounds(20, 170, 90, 20);

        jPanel2.add(baroalt);
        baroalt.setBounds(110, 170, 114, 22);

        jLabel10.setText("Vspeed:");
        jPanel2.add(jLabel10);
        jLabel10.setBounds(20, 200, 90, 20);

        jPanel2.add(vspeed);
        vspeed.setBounds(110, 200, 114, 22);

        jLabel11.setText("Course:");
        jPanel2.add(jLabel11);
        jLabel11.setBounds(20, 230, 90, 20);

        jPanel2.add(course);
        course.setBounds(110, 230, 114, 22);

        jLabel12.setText("GSpeed:");
        jPanel2.add(jLabel12);
        jLabel12.setBounds(20, 260, 90, 20);

        jPanel2.add(gspeed);
        gspeed.setBounds(110, 260, 114, 22);

        jLabel13.setText("Longitude:");
        jPanel2.add(jLabel13);
        jLabel13.setBounds(20, 320, 90, 20);

        jPanel2.add(latitude);
        latitude.setBounds(110, 290, 114, 22);

        jLabel14.setText("Latitude:");
        jPanel2.add(jLabel14);
        jLabel14.setBounds(20, 290, 90, 20);

        jPanel2.add(longitude);
        longitude.setBounds(110, 320, 114, 22);

        jLabel15.setText("Altitude:");
        jPanel2.add(jLabel15);
        jLabel15.setBounds(20, 350, 90, 20);

        jPanel2.add(altitude);
        altitude.setBounds(110, 350, 114, 22);

        jLabel16.setText("RPM:");
        jPanel2.add(jLabel16);
        jLabel16.setBounds(240, 20, 90, 20);

        jPanel2.add(rpm);
        rpm.setBounds(330, 20, 114, 22);

        jPanel2.add(pitch);
        pitch.setBounds(110, 80, 114, 22);

        jPanel2.add(roll);
        roll.setBounds(110, 50, 114, 22);

        jPanel2.add(state);
        state.setBounds(110, 20, 114, 22);

        jLabel17.setText("State:");
        jPanel2.add(jLabel17);
        jLabel17.setBounds(20, 20, 90, 20);

        jLabel18.setText("Roll:");
        jPanel2.add(jLabel18);
        jLabel18.setBounds(20, 50, 90, 20);

        jLabel19.setText("Pitch:");
        jPanel2.add(jLabel19);
        jLabel19.setBounds(20, 80, 90, 20);

        jLabel20.setText("Elevator:");
        jPanel2.add(jLabel20);
        jLabel20.setBounds(240, 140, 90, 20);

        jPanel2.add(elevator);
        elevator.setBounds(330, 140, 114, 22);

        jLabel21.setText("Rudder:");
        jPanel2.add(jLabel21);
        jLabel21.setBounds(240, 170, 90, 20);

        jPanel2.add(rudder);
        rudder.setBounds(330, 170, 114, 22);

        jLabel22.setText("Throttle:");
        jPanel2.add(jLabel22);
        jLabel22.setBounds(240, 200, 90, 20);

        jPanel2.add(throttle);
        throttle.setBounds(330, 200, 114, 22);

        jLabel23.setText("Flaps:");
        jPanel2.add(jLabel23);
        jLabel23.setBounds(240, 230, 90, 20);

        jPanel2.add(flaps);
        flaps.setBounds(330, 230, 114, 22);

        jLabel24.setText("Failures:");
        jPanel2.add(jLabel24);
        jLabel24.setBounds(240, 260, 90, 20);

        jPanel2.add(failures);
        failures.setBounds(330, 260, 114, 22);

        jLabel25.setText("Voltage:");
        jPanel2.add(jLabel25);
        jLabel25.setBounds(240, 290, 90, 20);

        jPanel2.add(voltage);
        voltage.setBounds(330, 290, 114, 22);

        jLabel26.setText("Current:");
        jPanel2.add(jLabel26);
        jLabel26.setBounds(240, 320, 90, 20);

        jPanel2.add(current);
        current.setBounds(330, 320, 114, 22);

        jLabel27.setText("Fuel:");
        jPanel2.add(jLabel27);
        jLabel27.setBounds(240, 350, 90, 20);

        jPanel2.add(fuel);
        fuel.setBounds(330, 350, 114, 22);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 458, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 458, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 389, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox aileron;
    private javax.swing.JComboBox airspeed;
    private javax.swing.JComboBox altitude;
    private javax.swing.JComboBox baroalt;
    private javax.swing.JTextField baudRate;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JTextField comPort;
    private javax.swing.JComboBox course;
    private javax.swing.JComboBox current;
    private javax.swing.JComboBox elevator;
    private javax.swing.JComboBox failures;
    private javax.swing.JComboBox flaps;
    private javax.swing.JComboBox fuel;
    private javax.swing.JComboBox gspeed;
    private javax.swing.JComboBox heading;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JComboBox latitude;
    private javax.swing.JComboBox longitude;
    private javax.swing.JComboBox pitch;
    private javax.swing.JTextField remoteAddr;
    private javax.swing.JTextField remotePort;
    private javax.swing.JComboBox roll;
    private javax.swing.JComboBox rpm;
    private javax.swing.JComboBox rudder;
    private javax.swing.JTextField selfAddr;
    private javax.swing.JTextField selfPort;
    private javax.swing.JRadioButton serial;
    private javax.swing.JComboBox state;
    private javax.swing.JComboBox temp1;
    private javax.swing.JComboBox temp2;
    private javax.swing.JComboBox throttle;
    private javax.swing.JRadioButton udp;
    private javax.swing.JComboBox voltage;
    private javax.swing.JComboBox vspeed;
    // End of variables declaration//GEN-END:variables

	private final String gr = AppConfig.GCS;
}
